//
//  AppDelegate.swift
//  swift-微博
//
//  Created by chenrin on 2016/12/13.
//  Copyright © 2016年 zhuoheng. All rights reserved.
//

import UIKit
import SVProgressHUD

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        NotificationCenter.default.addObserver(self, selector: #selector(rootVc), name: NSNotification.Name(rawValue: "rootVc"), object: nil)
        
        UINavigationBar.appearance().tintColor = UIColor.orange
        UITabBar.appearance().tintColor = UIColor.orange
        
        //1.创建Window
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        //2.创建根控制器
        window?.rootViewController = defaultContruller()
        window?.makeKeyAndVisible()
        
        return true
    }
    @objc private func rootVc(){
        window?.rootViewController = MainController()
    }
    private func defaultContruller() -> UIViewController{
        //检查用户是否登录
      
            if isNewupdate() {
                return NewFeatureController()
            }
         return MainController()
    }
    
// MARK:- 判断版本号
    private func isNewupdate() -> Bool{
        //1.获取当前版本号
       let currentVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
        //2.获取之前的版本号
        let sandboxVersion = UserDefaults.standard.object(forKey: "CFBundleShortVersionString") as? String ?? ""
        //3.比较当前和之前的版本号
        
        if currentVersion.compare(sandboxVersion) == ComparisonResult.orderedDescending{
            UserDefaults.standard.set(currentVersion, forKey: "CFBundleShortVersionString")
            return true
        }
        return false
    }
}

